<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <!-- 以借助 script 标签直接通过 CDN 来使用 Vue： -->
    <script src="./JS/vue.global.js"></script>
  </head>
  <body>
    <div id="app">
      <ul>
        <input type="text" placeholder=" 请输入名字" v-model="keyWord" />
        <li v-for="(p,index) of filPerons" :key="p.id">
          {{p.name}}-{{p.age}}-{{p.sex}}
        </li>
      </ul>
    </div>

    <script>
      Vue.createApp({
        data() {
          return {
            keyWord: "",
            persons: [
              {
                id: "001",
                name: "张三",
                age: 19,
                sex: "男",
              },
              {
                id: "002",
                name: "周冬雨",
                sex: "女",
                age: 18,
              },
              {
                id: "003",
                name: "马冬梅",
                age: 15,
                sex: "女",
              },
            ],
            // filPerons: [],
          };
        },
        // watch: {
        //   keyWord: {
        //     immediate: true,
        //     handler(val) {
        //       this.filPerons = this.persons.filter((p) => {
        //         return p.name.indexOf(val) !== -1;
        //       });
        //     },
        //   },
        // },

        computed: {
          filPerons() {
            return this.persons.filter((p) => {
              return p.name.indexOf(this.keyWord) !== -1;
            });
          },
        },
      }).mount("#app");
    </script>
  </body>
</html>
